module.exports = function(grunt) {

  grunt.initConfig({
    useminPrepare: {
      html: 'app/index.html',
      options: {
        dest: 'dist'
      }
    },
    filerev: {
      options: {
        algorithm: 'md5',
        length: 8
      },
      main: {
        src: 'dist/**/*.{js,css}'
      }
    },
    copy: {
      main: {
        files: [{
          expand: true,
          cwd: 'app',
          src: ['index.html', 'views/**/*.html', 'images/**/*', 'template/**/*'],
          dest: 'dist/'
        }, {
          expand: true,
          cwd: 'app/bower_components/bootstrap',
          src: ['fonts/**/*'],
          dest: 'dist/'
        }]
      }
    },
    clean: {
      dist: ['dist'],
      temp: ['.tmp']
    },
    usemin: {
      html: 'dist/index.html',
      options: {
        assetsDirs: ['dist']
      }
    }
  });

  // These plugins provide necessary tasks.
  grunt.loadNpmTasks('grunt-usemin');
  grunt.loadNpmTasks('grunt-contrib-concat');
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-contrib-cssmin');
  grunt.loadNpmTasks('grunt-contrib-copy');
  grunt.loadNpmTasks('grunt-contrib-clean');
  grunt.loadNpmTasks('grunt-filerev');

  // simple build task
  grunt.registerTask('build', [
    'clean:dist',
    'useminPrepare',
    'concat:generated',
    'cssmin:generated',
    'uglify:generated',
    'filerev',
    'copy',
    'usemin',
    'clean:temp'
  ]);
};